const express = require('express')

const cors = require('cors');

const app = express();

// 使用 cors 中间件来设置 CORS 策略
app.use(cors());


// 模拟大量数据
let mockData = [];
for (let i = 1; i <= 200; i++) {
    mockData.push({ id: i, name: `Item ${i}`, age: i, address: `Ottawa No. ${i} Lake Park`, });
}
app.get('/api/list', (req, res) => {
    const page = parseInt(req.query.page) || 1;  // 获取当前页码，默认第 1 页
    const pageSize = parseInt(req.query.pageSize) || 10;  // 获取每页显示数量，默认 10 条

    const start = (page - 1) * pageSize;
    const end = start + pageSize;

    const paginatedData = mockData.slice(start, end);
    setTimeout(() => {
        res.json({
            data: paginatedData,
            total: mockData.length
        });
    },3000)

});
app.listen(3000, () => {
    console.log('服务启动成功')
})